<?php
function echoPlayerStatsRow($team, $player, $row) {
    echo getEchoTR(($row +1), "center");
    echo "  <td align=left>" . getEchoValue($team->getRosterLink()) . "</td>\n";
    $name = $player->name;
    if (strlen($name) == 0) {
        $name = "#" . $player->rosterNum;
    }
    echo "  <td align=left>$player->link" . getEchoValue($name) . "</a></td>\n";
    echo "  <td align=left>" . getEchoValue($player->position) . "</td>\n";
    echo "  <td>" . getEchoValue($player->ma) . "</td>\n";
    echo "  <td>" . getEchoValue($player->st) . "</td>\n";
    echo "  <td>" . getEchoValue($player->ag) . "</td>\n";
    echo "  <td>" . getEchoValue($player->av) . "</td>\n";
    echo "  <td align=left><font size=\"-1\">" . getEchoValue($player->skills) . "</font></td>\n";
    echo "  <td>" . getEchoValue($player->getInjuries()) . "</td>\n";
    echo "  <td>" . getEchoValue($player->completions) . "</td>\n";
    echo "  <td>" . getEchoValue($player->tds) . "</td>\n";
    echo "  <td>" . getEchoValue($player->interceptions) . "</td>\n";
    echo "  <td>" . getEchoValue($player->casualties) . "</td>\n";
    echo "  <td>" . getEchoValue($player->mvps) . "</td>\n";
    echo "  <td>" . getEchoValue($player->exps) . "</td>\n";
    echo "  <td>" . getEchoValue($player->getSPPS()) . "</td>\n";
    echo "  <td align=\"right\">" . getEchoValue($player->cost) . "k</td>\n";
    echo "</tr>\n";
}

$showStats = true;
include_once ("includes/header.php");

$sort = getParam("sort");
$players = new Players($season);
$maSort = 7;
$stSort = 8;
$agSort = 9;
$avSort = 10;

switch ($sort) {
    case 1 :
        uasort($players->players, "playerCompletionsSort");
        break;
    case 2 :
        uasort($players->players, "playerTDsSort");
        break;
    case 3 :
        uasort($players->players, "playerInterceptionsSort");
        break;
    case 4 :
        uasort($players->players, "playerCasualtiesSort");
        break;
    case 5 :
        uasort($players->players, "playerMVPsSort");
        break;
    case 7 :
        uasort($players->players, "playerMaSort");
        $maSort = 11;
        break;
    case 8 :
        uasort($players->players, "playerStSort");
        $stSort = 12;
        break;
    case 9 :
        uasort($players->players, "playerAgSort");
        $agSort = 13;
        break;
    case 10 :
        uasort($players->players, "playerAvSort");
        $avSort = 14;
        break;
    case 11 :
        uasort($players->players, "playerMaReverseSort");
        break;
    case 12 :
        uasort($players->players, "playerStReverseSort");
        break;
    case 13 :
        uasort($players->players, "playerAgReverseSort");
        break;
    case 14 :
        uasort($players->players, "playerAvReverseSort");
        break;
    case 15 :
        uasort($players->players, "playerExpsSort");
        break;
    default :
        uasort($players->players, "playerSPPsSort");
}

// Touchdownss
echo<<< EOQ
            <caption><h1>$season->season Player Stats</h1></caption>
            <tr align="center">
              <th>Team</th>
              <th>Name</th>
              <th>Position</th>
              <th><a href="player_stats.php?sort=$maSort">ma</a></th>
              <th><a href="player_stats.php?sort=$stSort">st</a></th>
              <th><a href="player_stats.php?sort=$agSort">ag</a></th>
              <th><a href="player_stats.php?sort=$avSort">av</a></th>
              <th>Skills</th>
              <th>inj</th>
              <th><a href="player_stats.php?sort=1">cp</a></th>
              <th><a href="player_stats.php?sort=2">td</a></th>
              <th><a href="player_stats.php?sort=3">in</a></th>
              <th><a href="player_stats.php?sort=4">cs</a></th>
              <th><a href="player_stats.php?sort=5">mvp</a></th>
              <th><a href="player_stats.php?sort=15">exps</a></th>
              <th><a href="player_stats.php?sort=6">spp</a></th>
              <th>Cost</th>
            </tr>
EOQ;

$i = 0;
foreach ($players->players as $player) {
    $i++;
    if ($i > 25) {
        break;
    }
    echoPlayerStatsRow($teams->getTeam($player->teamId), $player, $i);
}
include ("includes/footer.php");
?>
